package cn.cc.compare;

import java.util.Comparator;

class StudentDemo{
    private String name ;
    private int age ;
    private int score;

    public StudentDemo(String name, int age, int score) {
        this.name = name ;
        this.age = age ;
        this.score  = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }
}
class StudentComparator implements Comparator<StudentDemo>{
    @Override
    public int compare(StudentDemo o1, StudentDemo o2) {
        if (o1.equals(o2)) {
            return 0 ;
        } else if (o1.getAge() < o2.getAge()) {
            return -1 ;
        }
        else{
            return 1 ;
        }
    }
}
public class Compator {
    public static void main(String[] args) {
        StudentDemo[] stu={
                new StudentDemo("张三",20,89),
                new StudentDemo("李四",26,53),
                new StudentDemo("王五",30,79),
                new StudentDemo("赵六",20,66),
                new StudentDemo("孙七",25,66)
        };
        java.util.Arrays.sort(stu,new StudentComparator());	//进行排序操作
        for(StudentDemo x:stu){	//循环输出
            System.out.println(x);
        }

    }
}
